/*
 * Qinlan Shen
 * November 8, 2010
 * Pd. 8
 * 
 * Script, based off of Sanae's Miracle Fruit.  Difficulty and time limit
 * can be adjusted.
 * 
 */

import java.awt.Image;
import java.util.*;

public class MiracleFruit extends RoseScript
{
	private int radius;
	private int length;
	private int angle;
	private int angle2;
	private int frame2;
	
	public MiracleFruit(int d, int t) {
		super(d - 4, t);
		radius = 75;
		length = 400;
		angle = 0;
		angle2 = 0;
		frame2 = 0;
	}


	public ArrayList<PointItem> run(Rose rose, Character player, int frame, ArrayList<Enemy> enemies, ArrayList<PointItem> points, ArrayList<Image> packets, Image point)
	{
		incrementTime(frame);
			
		if (frame == 0 && frame2 == 0)
			rose.moveUsingFrames(320, 375, 60);
		else if (frame2 == 0)
			rose.randomMove(100, 50, 60);
		else if(difficulty > 10 && frame2 >= 80 && frame2  < 80 + length/10)
		{
			angle = 0;
			angle2 = 0;
			for (int i = 0; i < difficulty; i++)
			{
				for(int j = 0; j < 20; j++)
				{
					if (frame % 4 == 0)
						enemies.add(new PacketSA(packets.get(0), 3, (int)Math.round(rose.getX() + radius * Math.sin(Math.toRadians(angle))), (int)Math.round(rose.getY() + radius * Math.cos(Math.toRadians(angle))), 3, -angle2, 0, .1));
					angle2 += 18;
				}
				angle += 360/difficulty;
			}
		}
		else if(difficulty <= 10 && frame2 >= 120 && frame2  < 120 + length/10)
		{
			angle = 0;
			angle2 = 0;
			for (int i = 0; i < difficulty; i++)
			{
				for(int j = 0; j < 20; j++)
				{
					if (frame % 4 == 0)
						enemies.add(new PacketSA(packets.get(0), 3, (int)Math.round(rose.getX() + radius * Math.sin(Math.toRadians(angle))), (int)Math.round(rose.getY() + radius * Math.cos(Math.toRadians(angle))), 2, -angle2, 0, .1));
					angle2 += 18;
				}
				angle += 360/difficulty;
			}
		}
		else if (difficulty > 10 && frame2 >= 80 + length/10 || difficulty <= 10 && frame2 >= 120 + length/10)
			frame2 = -1;

		
		frame2++;
		if (time < 0)
			points = endScript(point, rose, player, enemies);
		
		return points;
	}
}